program define createvarsacad
/*
hidegree:
1 LICENCIATURA
2 POSGRADUACAO
3 MESTRADO
4 DOUTORAMENTO

category:
1 ASSISTENTE
2 ASSISTENTE CONVIDADO
3 ASSISTENTE ESTAGIARIO
4 CARREIRA INVESTIGACAO
5 INVESTIGADOR AUXILIAR
6 INVESTIGADOR AUXILIAR CONVIDADO
7 INVESTIGADOR COORDENADOR
8 PROFESSOR ASSOCIADO
9 PROFESSOR ASSOCIADO CONVIDADO
10 PROFESSOR AUXILIAR
11 PROFESSOR AUXILIAR CONVIDADO
12 PROFESSOR CATEDRATICO
13 PROFESSOR CATEDRATICO CONVIDADO

regpres:
1 DEDICACAO EXCLUSIVA
2 TEMPO INTEGRAL
3 TEMPO PARCIAL 

*/
gen doctor=(hidegree==4)
tempvar dum
bys name (year): gen `dum'=sum(category==10)
gen dfpaux=(`dum'==1) & (category==10)
label var dfpaux "first time as Prof Auxiliar"
drop `dum'
bys name (year): gen `dum'=sum(category==8)
gen dfpass=(`dum'==1) & (category==8)
label var dfpass "first time as Prof Associado"
drop `dum'
bys name (year): gen `dum'=sum(category==12)
gen dfpcat=(`dum'==1) & (category==12)
label var dfpcat "first time as Prof Catedratico"
drop `dum'
sort name year
gen dumpaux=(category==10) & (category[_n-1]==1 | category[_n-1]==3) & (name==name[_n-1])  
label var dumpaux "Assist to Prof Auxiliar"
gen dumpass=(category==8) & (category[_n-1]==10) & (name==name[_n-1])
label var dumpass "Prof Aux to Prof Associado"
gen dumpcat=(category==12) & (category[_n-1]==8 | category[_n-1]==10) & (name==name[_n-1])
label var dumpcat "Prof Assoc to Prof Catedratico"
gen dpauxih=(dumpaux==1)&(mainaff==mainaff[_n-1])
label var dpauxih "In-house Assist to Prof Auxiliar"
gen dpassih=(dumpass==1)&(mainaff==mainaff[_n-1])
label var dpassih "In-house Prof Aux to Prof Associado"
gen dpcatih=(dumpcat==1)&(mainaff==mainaff[_n-1])
label var dpcatih "In-house Prof Assoc to Prof Catedratico" 
* tenure variable 
gen tenure=0
clonevar newcat=category
* recode investigadores to profs
recode newcat (4 5=10) (7=12)
* Count only prof aux, ass e cat
replace tenure=1 if newcat==8 | newcat==10 | newcat==12
* exclude partial links
replace tenure=0 if regpres==0
* Now drop those without PhDs (most likely are "CONVIDADOS")
tempvar max
bys name: egen `max'=max(hidegree)
replace tenure=0 if `max'<4
drop `max'
* label variables
label variable dfpaux "First time as Assistant Professor ('Auxiliar')"
label variable dumpaux "Promotion to Assistant Professor ('Auxiliar')"
label variable dpauxih "In-house promotion to Assistant Professor ('Auxiliar')"
label variable dfpass "First time as Associate Professor ('Associado')"
label variable dumpass "Promotion from Assistant to Associate Professor ('Auxiliar' - 'Associado')"
label variable dpassih "In-house promotion from Assistant to Associate Prof. ('Auxiliar'/'Associado')"
label variable dfpcat "First time as Full Professor ('Catedratico')"
label variable dumpcat "Promotion from Associate to Full Prof. ('Catedratico')"
label variable dpcatih "In-house promotion to Full Professor ('Catedratico')"
label variable tenure "tenure-track professors"
end










/*
*/


*/
